package com.lingchen.boot.utils;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Collections;
import java.util.Random;
import java.util.UUID;
import java.util.stream.Collectors;

/**
 * I'm a cute code dog
 * User: LingChen
 * Date:2017/9/28
 * Time:10:47
 */
public class UuidUtils {
    public static String getUUID(int number) {
        if (number < 1) {
            return null;
        }
        String[] retArray = new String[number];
        for (int i = 0; i < number; i++) {
            retArray[i] = getUUID();
        }
        String join = StringUtils.join(retArray);
        return join;
    }

    public static String getUUID() {
        String uuid = UUID.randomUUID().toString();
        //去掉“-”符号
        return uuid.replaceAll("-", "");
    }

    public static String getlengthString(int length) {
        if (length > 32) {
            return null;
        }
        String uuid = UUID.randomUUID().toString();
        //去掉“-”符号
        String uu = uuid.replaceAll("-", "");
        return uu.substring(0, length);
    }


    public static int getRanNumBy8() {
        return (int)((Math.random()*9+1)*10000000);
    }
    public static int getRanNumBy10() {
        return (int)((Math.random()*9+1)*1000000000);
    }
    public static String getRandomString(int length) { //length表示生成字符串的长度
        String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }



    public static void main(String[] args) {

        System.out.println( getRandomString(240));
    }
}
